package com.jing.cloud.service.chat.config;

import com.jing.cloud.service.chat.adapter.MessageAdapter;
import com.jing.cloud.service.chat.adapter.handler.MessageHandler;
import com.jing.cloud.service.config.SpringConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

/**
 * Created by 29017 on 2017/9/10.
 */
@Component
public class MessageHandlerConfig {
    @Autowired
    private SpringConfig springConfig;

    @PostConstruct
    private void init() {
        Map<String, MessageHandler> messageHandlerMap = springConfig.getAppCtx().getBeansOfType(MessageHandler.class);
        Collection<MessageHandler> messageHandlers = messageHandlerMap.values();
        ArrayList<MessageHandler> arrayList = new ArrayList<>(messageHandlers);
        Collections.sort(arrayList);
        MessageAdapter.setMessageHandlers(arrayList);
    }
}
